using System.Security.Claims;
using Backoffice.Application.Common.Interfaces;
using Microsoft.AspNetCore.Http;

namespace Backoffice.Application.Common.Services
{
    public sealed class CurrentUser : ICurrentUser
    {
        private readonly IHttpContextAccessor _ctx;
        public CurrentUser(IHttpContextAccessor ctx) => _ctx = ctx;

        public Guid UserId =>
            Guid.Parse(_ctx.HttpContext?.User.FindFirstValue(ClaimTypes.NameIdentifier) ?? Guid.Empty.ToString());

        public string? UserName =>
            _ctx.HttpContext?.User.FindFirstValue(ClaimTypes.Name);

        public IEnumerable<Claim> Claims =>
            _ctx.HttpContext?.User.Claims ?? Enumerable.Empty<Claim>();
    }
}